package net.borlis.sample.service.repositories.schema;

import org.apache.commons.configuration.PropertiesConfiguration;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author alex@borlis.net on 23.07.2014.
 */
@ApplicationScoped
public class SchemaConfiguration implements ISchemaConfiguration {

    @Inject
    private Logger logger;

    private String schemaConfiguration;

    @PostConstruct
    public void init(){
        try {
            PropertiesConfiguration localSettings = new PropertiesConfiguration("jdbc.properties");
            schemaConfiguration = localSettings.getString("schema.vito");
        } catch (Exception cex) {
            logger.log(Level.SEVERE, cex.getMessage(), cex);
            throw new SchemaConfigurationInitError(cex);
        }
    }

    @Override
    public String getSchemaConfiguration() {
        return schemaConfiguration;
    }
}
